package edu.cornell.cubooks.dao;

import edu.cornell.cubooks.domain.User;

/**
 * Data Access Object interface for users.
 * 
 * @author CUBooks Team
 *
 */
public interface UserDao extends GenericDao<User, Integer> {
	
	/**
	 * Checks if user with specific username exists in the database.
	 * 
	 * @param username the username
	 * @return true if user exists and false otherwise
	 */
	public boolean userNameExists(String username);
	
	/**
	 * Checks if user with specific username exists in the database.
	 * 
	 * @param username the username
	 * @return true if user exists and false otherwise
	 */
	public boolean userNameExistsForOtherUser(String username, int id);

	/**
	 * Creates token for given user.
	 * 
	 * @param user
	 */
	public String createToken(User user);
	
	/**
	 * Loads user based on given email.
	 * @param token
	 */
	public User loadUserByEmail(String email);
	
	/**
	 * Validates token for given user.
	 * 
	 * @param user
	 * @return
	 */
	public boolean checkToken(User user, String token);
	
	/**
	 * Updates failed login attempts for given username.
	 * 
	 * @param username
	 */
	public void updateFailLoginAttepmts(String username);
	
	/**
	 * Changes users password.
	 * @param user
	 */
	public void changePassword(User user);

	/**
	 * Checks if user with specific email address exists in the database.
	 * 
	 * @param email the email address
	 * @return true if email exists and false otherwise
	 */
	public boolean emailExists(String email);
	
	/**
	 * Checks if user with specific email address exists in the database.
	 * 
	 * @param email the email address
	 * @return true if email exists and false otherwise
	 */
	public boolean emailExistsForOtherUser(String email, int id);
	
	/**
	 * Encrypts password and updates given user.
	 * 
	 * <p>
	 * Note: This is an alias for {@link UserDao.changePassword} method.
	 * </p>
	 * @param user
	 */
	public void updateWithPasswordEncryption(User user);
	
	/**
	 * Approves given user to be seller.
	 * @param user
	 */
	public void approveSeller(User user);
	
	/**
	 * Authenticates given user.
	 * 
	 * @param user
	 */
	//public void authenticate(String username, String password);
	
}
